import Vuex from 'vuex'
import Vue from 'vue'
import moudelProduct from './module/product'
Vue.use(Vuex)

Vue.config.productionTip = false
var sto ={
    state: {
      count: 0,
      name: 'hello',
      todos: [
        { id: 1, text: '你', done: true },
        { id: 2, text: '好', done: false },
        { id: 3, text: '呀', done: true },
        { id: 4, text: '!', done: false },
      ],
      shopinfo:[
        {
            id:1,
            shopname:'荔枝',
            num:1
        },
        {
            id:2,
            shopname:'芒果',
            num:1
        },
        {
            id:3,
            shopname:'桃子',
            num:0
        },
        {
            id:4,
            shopname:'apple',
            num:0
        },
    ],
  
    },
    
   
    mutations: {
      increment (state,num) {
        state.count+= num
      },
      updateName:(state,newname)=>{
        state.name=newname
      }
    },
    actions:{
      getName:(ctx,token)=>{
        setTimeout (()=>{
          console.log('延时两秒执行')
        },2000)
        // ctx.state.name=token
        ctx.commit('updateName',token)
      }
    },
    module:{
     product:moudelProduct
    },
    getters: {
      todoDone: state => {
        return state.todos.filter(item => item.done===true)
      },
      todoDoneCount:(state,getters)=>{
        return getters.todoDone.length
      },
      name2:state=>{
        return '中国你好'+state.name
    },
    shopinfoRight:state=>{
        return state.shopinfo.filter(item=>item.num)
    },
    shopinfounRight:state=>{
        return state.shopinfo.filter(item=>!item.num)
    },
    }
    
  }
const store = new Vuex.Store(sto)

store.commit('increment',10)
store.commit('updateName','兰博基尼')
console.log(store.state.count)
export default store